package cn.com.huzo.service.trade.impl;

import cn.com.huzo.model.entities.trade.ProductionInstructionLinesSuitSizeEntity;
import cn.com.huzo.repository.trade.ProductionInstructionLinesSuitSizeRepository;
import cn.com.huzo.service.trade.ProductionInstructionLinesSuitSizeManager;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import huzofw.service.impl.GenericManagerImpl;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.apache.commons.collections4.MapUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 生产指示书明细尺码管理服务对象类实现。
 *
 * @author 吴旭
 */
@Service("ProductionInstructionLinesSuitSizeManager")
public class ProductionInstructionLinesSuitSizeManagerImpl extends GenericManagerImpl<ProductionInstructionLinesSuitSizeEntity, String>
        implements ProductionInstructionLinesSuitSizeManager {

    @Resource(name = "ProductionInstructionLinesSuitSizeRepository")
    private ProductionInstructionLinesSuitSizeRepository _dao_lines_suit_size;

    /**
     * {@inheritDoc}
     *
     * @throws java.lang.Exception
     */
    @Transactional
    @Override
    public List<ProductionInstructionLinesSuitSizeEntity> fetchSuitSizeByParentLinesId(String parentLinesId) throws Exception {
        return _dao_lines_suit_size.fetchByParentLinesId(parentLinesId);
    }

    /**
     * {@inheritDoc}
     *
     * @throws java.lang.Exception
     */
    @Transactional
    @Override
    public Map<String, Object> saveSuitSize(Map<String, Object> criterion) throws Exception {
        Map<String, Object> _result = new HashMap();

        ObjectMapper mapper = new ObjectMapper();
        List<ProductionInstructionLinesSuitSizeEntity> itemList = mapper.convertValue(MapUtils.getObject(criterion, "UpdateList"), new TypeReference<List<ProductionInstructionLinesSuitSizeEntity>>() {
        });

        // 更新
        if (!itemList.isEmpty()) {
            Integer rowsAffected = _dao_lines_suit_size.batchUpdate(itemList);

            if (rowsAffected > 0) {
                //writeAuditLog(MapUtils.getLong(_updateList.get(i), "UpdatedBy"), "贸易信息→生产指示书明细",
                //        "[款号]" + MapUtils.getString(_updateList.get(i), "StyleNo") + " [交付日期]" + MapUtils.getString(_updateList.get(i), "OldScheduleDate") + "==>" + MapUtils.getString(_updateList.get(i), "NewScheduleDate"),
                //        "更新");
                _result.put("SuitSizeName", MapUtils.getString(criterion, "SuiteSizeName"));
            }
        }

        return _result;
    }
}
